﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrmHotel
{
    public partial class FrmUpdateShangPinInfo : Form
    {
        public FrmUpdateShangPinInfo()
        {
            InitializeComponent();
        }
        public int id;//接收商品编号
        private void FrmUpdateShangPinInfo_Load(object sender, EventArgs e)
        {
            string sql2 = "select * from  CommodityClass";
            DataTable dt2 = DBHelper.SelectForTable(sql2);
            DataRow dr2 = dt2.NewRow();
            dr2["ClassId"] = 0;
            dr2["ClassName"] = "请选择";
            dt2.Rows.InsertAt(dr2, 0);
            this.comboBox1.DisplayMember = "ClassName";
            this.comboBox1.ValueMember = "ClassId";
            this.comboBox1.DataSource = dt2;

            string sql = string.Format("select * from Commodity where CyId={0}",id);
            SqlDataReader reader = DBHelper.SelectMore(sql);
            if (reader.Read())
            {
                this.textBox1.Text = reader["CyName"].ToString();
                this.comboBox1.SelectedValue = reader["CyClass"];
                this.textBox2.Text = reader["CyPrice"].ToString();
            }
            reader.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string name = this.textBox1.Text;
            int ih = Convert.ToInt32(this.comboBox1.SelectedValue);
            string danjia = this.textBox2.Text;
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(danjia))
            {
                MessageBox.Show("请填写完整商品信息！", "提示信息！");
                return;
            }
            if (ih == 0)
            {
                MessageBox.Show("请选择商品类型！", "提示信息！");
                return;
            }
            string sql = string.Format("update  Commodity set CyName='{0}',CyPrice={1},CyClass={2} where CyId={3} ",name, danjia, ih, id);
            int Z1 = Convert.ToInt32(DBHelper.ExecuteUpdate(sql));
            if (Z1 > 0)
            {
                MessageBox.Show("修改成功！", "提示信息！");
            }
            else
            {
                MessageBox.Show("修改失败！", "提示信息！");
                return;
            }
        }
    }
}
